package cn.initcap.util;

import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Properties;

/**
 * @author initcap
 * @date 2018/8/10 PM4:38
 */
public class DataBaseUtil {

    private static Properties props;

    static {
        try {
            InputStream in = DataBaseUtil.class.getClassLoader().getResourceAsStream("database.properties");
            props = new Properties();
            props.load(in);
            in.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static Connection getConn() throws Exception {
        String url = props.getProperty("url");
        String username = props.getProperty("username");
        String password = props.getProperty("password");
        String driver = props.getProperty("driver-class-name");
        Class.forName(driver);
        return DriverManager.getConnection(url, username, password);
    }
}
